/*
 * delay.c
 *
 *  Created on: Mar 28, 2011
 *      Author: Vishal Verma
 */

#include <at89c51ed2.h>  //also includes 8052.h and 8051.h
#include <mcs51reg.h>
#include "delay.h"

/*
* NAME :            delay_millisec
*
* DESCRIPTION :     provide approx millisec delay
*
* INPUTS :
*       PARAMETERS:	delay
*		GLOBALS:	
*
* OUTPUTS :
*		PARAMETERS: 
*       GLOBALS :	
*       RETURN :	
*
* PROCESS :
*                   [1]  
*
* NOTES :           
*/

void delay_millisec(unsigned int delay)
{
	/* A subroutine for generating 1ms delay */

	TMOD |= 0x01; 						// timer 0; mode 1
	TH0 = 0xFC;
	TL0 = 0x66;							// with 11.0592 MHz crystal

	for (  ; delay != 0; delay-- ) {

		TR0 = SET; 						// start timer

		while(TF0 == CLEAR)
			; 							// wait for timer overflow 
		TF0 = CLEAR;		 			// clear flags 
	}
	TR0 = CLEAR; 						// stop timer 
}
